package com.yibo.yunpicture.domain.user.valueobject;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

/**
 * 用户角色枚举
 */
@Getter
public enum UseRoleEnum {
    USER("用户", "user"),
    ADMIN("管理员", "admin");

    private final String text;
    private final String value;

    UseRoleEnum(String text, String value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 根据value获取枚举值
     */
    public static UseRoleEnum getUseRoleEnumByValue(String value) {
        if(ObjectUtil.isEmpty(value)){
            return null;
        }
        for (UseRoleEnum useRoleEnum : UseRoleEnum.values()) {
            if (useRoleEnum.getValue().equals(value)) {
                return useRoleEnum;
            }
        }
        return null;
    }
}
